package com.bo.client.Controller;

import java.io.OutputStream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.bo.Entity.MyImage;
import com.bo.Service.CompanyIntService;
import com.bo.Service.CompanyService;
import com.bo.Service.CompanyTouchService;
import com.bo.Service.ProductService;


@Controller
public class CreateImageController {
	  
	@Autowired
	private CompanyIntService companyIntService;
	
	@Autowired
	private CompanyTouchService companyTouchService;
	
	@Autowired
	private ProductService productService;
	
	
	@Autowired
	private CompanyService companyService;
	

	
	@RequestMapping(value="/image/{dir}/Img.do", method=RequestMethod.GET)
	public void getImage(@PathVariable("dir") String dir,@RequestParam("id") int id
			             ,@RequestParam("index") int index,OutputStream outputStream
			             ,@RequestParam(value="width",required=false) Integer width
			             ,@RequestParam(value="height",required=false) Integer height){
		
		
		if(dir.equalsIgnoreCase("CompanyList")){
			
			companyService.getImage(id, new MyImage(index,outputStream,width,height));
			
		}else if(dir.equalsIgnoreCase("CompanyInt")){
			
			companyIntService.getImage(id, new MyImage(index,outputStream,width,height));
			
		}else if(dir.equalsIgnoreCase("Product")||dir.equalsIgnoreCase("ProductList")){
			
			productService.getImage(id, new MyImage(index,outputStream,width,height));
			
		}else if(dir.equalsIgnoreCase("CompanyTouch")){
			
			companyTouchService.getImage(id, new MyImage(index,outputStream,width,height));
			
		}
	
	}

}
